var SpriteDirectionFactory = {
	fromBean: function( bean ) {
		var direction = new SpriteDirection();
		direction.setName( bean.name );
		direction.setDelta( Point2dFactory.fromBean( bean.delta ) );
		direction.setFrames( Point2dFactory.fromBeans( bean.frames ) );
		return direction;
	}
	, fromBeans: function( beans ) {
		return Util.each( 
			beans
			, function( bean ) { return SpriteDirectionFactory.fromBean( bean ); }
		);
	}
};

var SpriteDirection = function() {
	this.setFrameIndex = function( frameIndex ) {
		this.frameIndex_ = frameIndex;
	};

	this.getFrameIndex = function() {
		return this.frameIndex_;
	};

	this.setName = function( name ) {
		this.name_ = name;
	};

	this.getName = function() {
		return this.name_;
	};

	this.setDelta = function( delta ) {
		this.delta_ = delta;
	};

	this.getDelta = function() {
		return this.delta_;
	};

	this.setFrames = function( frames ) {
		this.frames_ = frames;
	};

	this.getFrames = function() {
		return this.frames_;
	};

	this.init = function() {
		this.setFrames( [] );
		this.setFrameIndex( 0 );
	};

	this.move = function() {
		var next = this.getFrameIndex() + 1;
		if ( next >= this.getFrames().length ) { 
			next = 0;
		}
		this.setFrameIndex( next );
	};

	this.getCurrentFrame = function() {
		return this.getFrames()[ this.getFrameIndex() ];
	};

	this.init();
};
